package Luogu;

import java.util.Scanner;

public class test2 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String team =sc.nextLine();
        String planet =sc.nextLine();
        long numTeam = getNumber(team);
        long numPlanet = getNumber(planet);
//        System.out.println(numTeam);
//        System.out.println(numPlanet);

        if((numPlanet%47)==(numTeam%47)){
            System.out.println("GO");
        }
        else{
            System.out.println("STAY");
        }
    }

    private static long getNumber(String str) {
        long count=(int)str.charAt(0)-64;
//        System.out.println("count"+count);
        for (int i = 1; i < str.length(); i++) {
            long num = (int)str.charAt(i)-64;
            count=count*num;
        }
        return count;
    }
}
